package com.dz.control;

import com.dz.bean.guanli;
import com.dz.bean.user;
import com.dz.dao.guanliMapper;
import com.dz.dao.userMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

@Controller
public class shouye {
    @Autowired
    com.dz.dao.Dingdan02Mapper dingdan02Mapper;

    @RequestMapping({"/login","/"})
    public String login(){
        return "login";
    }

    @Resource
    guanliMapper guanliMapper;

    @RequestMapping("loginList")
    @ResponseBody
    public List login01(HttpServletRequest request){
        String us = request.getParameter("username");
        String ps = request.getParameter("password");
        guanli g1 =new guanli();
        g1.setAname(us);
        g1.setApsw(ps);
        List list=  guanliMapper.login(g1);

        return list;
    }

    @RequestMapping("/order-list")
    public String order(){
        return "order-list";
    }
    @RequestMapping("/order-list1")
    public String order1(){
        return "order-list1";
    }
    @GetMapping("/admin-list")
    public String admin(){
        return "admin-list";
    }

    @GetMapping("/admin-role")
    public String admin01(){
        return "admin-role";
    }

    @GetMapping("/admin-cate")
    public String admin02(){
        return "admin-cate";
    }

    @GetMapping("/admin-rule")
    public String admin03(){
        return "admin-rule";
    }

    @GetMapping("/admin-add")
    public String adminAdd(){
        return "admin-add";
    }

    @GetMapping("/cate")
    public String adminAdd00(){
        return "cate";
    }
    @GetMapping("/user.json")
    public String adminAdd01(){
        return "user.json";
    }


    @RequestMapping({"/index","/index.html"})
    public String index(){
        return "index";
    }

    @RequestMapping("/welcome")
    public String we(){
        return "welcome";
    }

    @RequestMapping("/welcome1")
    public String we0(){
        return "welcome1";
    }


    @RequestMapping("/geren")
    public String we2(){
        return "geren.html";
    }


    @GetMapping("/member-edit")
    public String we3(){
        return "member-edit";
    }
    @RequestMapping("/member-list")
    public String we1(){
        return "member-list";
    }
//    @RequestMapping("/member-list1")
//    public String we2(){
//        return "member-list1";
//    }
    @Autowired
    userMapper userMapper;
    @ResponseBody
    @RequestMapping("/list")
    public List<user> list01(Model model,HttpServletRequest request) {

        List<user> list = userMapper.selectAll();
//        System.out.println(list.toString());
        int boy=0;
        int girl=0;
        for (int i = 0; i < list.size(); i++) {
           if("男".equals(list.get(i).getSex())) {
               boy++;
           }else if("女".equals(list.get(i).getSex())){
               girl++;
            }
        }
        request.getSession().setAttribute("boy",boy);
//        model.addAttribute("boys",boy);
//        model.addAttribute("girl",girl);
        System.out.println("boy"+boy+" "+"gilr"+girl);

//        localStorage.setItem('user',values.username);
//        sessionStorage

        return list;

    }


    @ResponseBody
    @RequestMapping("/keshihua")
    public Map list02(Model model,HttpServletRequest request) {

        List<user> list = userMapper.selectAll();
//        System.out.println(list.toString());
        int boy=0;
        int girl=0;
        for (int i = 0; i < list.size(); i++) {
            if("男".equals(list.get(i).getSex())) {
                boy++;
            }else if("女".equals(list.get(i).getSex())){
                girl++;
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("boy",boy);
        map.put("girl",girl);
//        request.getSession().setAttribute("boys",boy);
//        model.addAttribute("boy",boy);
//        model.addAttribute("girl",girl);

//        localStorage.setItem('user',values.username);
//        sessionStorage
        return map;

    }

    @ResponseBody
    @RequestMapping("/list00")
    public List<user> list(HttpServletRequest request){

        List<user> list = userMapper.selectAll();
        request.getSession().setAttribute("list",list);


        return list;

    }
//    @ResponseBody
    @RequestMapping("/member-add")
    public String member(){


        return "member-add";
    }

    @RequestMapping("/member-del")
    public String member01(){


        return "member-del";
    }

    @RequestMapping("/member-list1")
    public String member02(){


        return "member-list1";
    }




}
